home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / exampl1.spr < prev    next >
Text File  |  1980-01-01  |  3KB  |  65 lines

  1. /* example1.spr */
  2. /* This is the first example file that comes with Small Prolog.
  3.    To load it:
  4.    First run sprolog by typing sprolog at the DOS level.
  5.    Then type (consult "example1.spr") and follow that
  6.    by a carriage return.
  7.    Then try asking questions (more about that below).
  8.    When you want to leave type (quit) or a control-c.
  9.    
  10.    What are questions?
  11.    First a little background:
  12.    Prolog can be used as a "declarative language". 
  13.    Ideally this would be that you could program forgetting how your program 
  14.    works -you would only have to tell it what is true, 
  15.    rather than how to go about answering you.
  16.    Then you would just ask questions to verify a fact or ask for a value.
  17.    In practice things aren't that perfect, but you can often program
  18.    without caring about the procedure that prolog uses to answer your
  19.    question. The simplest example is using Prolog as just a database
  20.    language, and this is what we shall do below. We have entered a
  21.    set of Prolog facts. Each fact starts with a name for a relation
  22.    and then some arguments. The meaning is of course your problem,
  23.    just as in any traditional database. Of course we are not storing
  24.    facts on disk, but rather in the "heap space" (part of RAM).
  25.  
  26.    Asking a question is like executing a database query.
  27.    You type an expression that looks just like a fact, except
  28.    that it typed at the level of the interpreter and it may 
  29.    contain variables (which begin with capital letters).
  30.    So try loading this file and type the following questions.
  31.    Do not type them here in this file!
  32.    for example:
  33.  
  34.    (composer_period chopin baroque)
  35.    (composer_period Who baroque)
  36.    (composer_period Who Period)
  37.    (composer_period beethoven Period)
  38.  
  39.    Don't forget that constants must begin with a small letter.
  40.    If you dont'like this then change the source code!.
  41.    Prolog will answer a question ( or query) by trying to match
  42.    the question with some fact, It starts with the first fact
  43.    and moves downwards. When it works it gives you an answer,
  44.    and then if there are untried facts it will ask you if you
  45.    want to see if there are any more answers. You must answer y or n.
  46.    The matching process in prolog is called unification.   
  47. */
  48.  
  49. (composer_period chopin romantic)
  50. (composer_period brahms romantic)
  51. (composer_period berlioz romantic)
  52. (composer_period bach baroque)
  53. (composer_period vivaldi baroque)
  54. (composer_period telleman baroque)
  55. (composer_period stravinsky contemporary)
  56. (composer_period messiaen contemporary)
  57. (composer_period ives contemporary)
  58. (composer_period mozart classical)
  59. (composer_period haydn classical)
  60. (composer_period lutoslawski contemporary)
  61. (composer_period beethoven classical)
  62. (composer_period beethoven romantic)/* yes, both !! */
  63. (composer_period tchaikovsky romantic)
  64.  
  65.